import { createApp } from 'vue'
import Message from './Message.vue'

// 让我们可以使用函数调用的方式创建Message组件
function createMessage({ message, type }) {
  const messageInstance = createApp(Message, {
    message,
    type
  })

  const mountNode = document.createElement('div')
  document.body.appendChild(mountNode)

  messageInstance.mount(mountNode)
  setTimeout(() => {
    messageInstance.unmount()
    mountNode.parentNode.removeChild(mountNode)
  }, 3000)
}

export default createMessage
